package com.ymatou.iapi.optrade.testcase;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFeeTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFreightTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.ApplyRefundReq;
import com.ymatou.iapi.optrade.parameter.req.ChangeRefundBillV2Req;
import com.ymatou.iapi.optrade.parameter.vo.SalesRefundInfoVo;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.ChangeRefundBillV2Call;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAuthenticateCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;

/**
 * 更新退货退款信息接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ChangeRefundBillV2 {

	private static ChangeRefundBillV2Req changeRefundBillReq;
	private static ChangeRefundBillV2Call changeSalesRefundInfoCall;
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	
	private static long userId = 20238699;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新退货退款信息接口-买家");
	}

	@Before
	public void caseUp() {
		changeRefundBillReq = new ChangeRefundBillV2Req();
		changeSalesRefundInfoCall = new ChangeRefundBillV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(changeSalesRefundInfoCall.getOpurl());
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_001() {
		Logger.start(true, "更新退货退款信息成功");
		try {

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true, BigDecimal.TEN,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			Long orderId = order.getOrderId();

			long sellerId = order.getSellerId();

			BigDecimal orderFreight = order.getOrderFreight();

			BigDecimal proFreight = order.getOrderDetailPoList().get(0)
					.getFreight();

			//支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			//接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			//申请改订单下第一个商品退款
			ApplyRefundReq applyRefundReq = RefundService
					.buildStandApplyRefundReq(order);

			SalesRefundInfoVo oldRefundInfoVo = applyRefundReq
					.getSalesRefundInfoList().get(0);

			applyRefundReq.setSalesRefundInfoList(Arrays
					.asList(oldRefundInfoVo));

			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(oldRefundInfoVo
					.getRefundBillNo());
			changeRefundBillReq.setCatalogId(oldRefundInfoVo.getCatalogId());

			changeRefundBillReq.setApplyRefundAmount(oldRefundInfoVo
					.getRefundAmount().add(orderFreight.subtract(proFreight)));

			changeRefundBillReq.setApplyRefundCount(oldRefundInfoVo
					.getRefundProductNum());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			String refundBillNo = oldRefundInfoVo.getRefundBillNo();

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);

			expectedRefundBillPo.setCatalogId(oldRefundInfoVo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(oldRefundInfoVo
					.getRefundAmount().add(orderFreight.subtract(proFreight)));

			expectedRefundBillPo.setProductCount(oldRefundInfoVo
					.getRefundProductNum());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);

			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_002() {
		Logger.start(false, "订单号不存在");
		try {
			changeRefundBillReq.setOrderId(111111);
			changeRefundBillReq.setRefundBillNo("1233");
			changeRefundBillReq.setCatalogId("1111111");
			changeRefundBillReq.setApplyRefundAmount(new BigDecimal(100));
			changeRefundBillReq.setApplyRefundCount(100);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口Code");

			Logger.verifyEquals(
					String.format("退款单%s不存在",
							changeRefundBillReq.getRefundBillNo()),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证更新退货退款接口Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_003() {
		Logger.start(false, "退款单号不存在");
		try {
			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 申请退款
			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo("1111111");
			changeRefundBillReq.setApplyRefundAmount(new BigDecimal(1));
			changeRefundBillReq.setCatalogId("22222222");
			changeRefundBillReq.setApplyRefundCount(100);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口Code");

			Logger.verifyEquals(
					String.format("退款单%s不存在",
							changeRefundBillReq.getRefundBillNo()),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证更新退货退款接口Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_004() {
		Logger.start(false, "申请退款金额大于实际可退款金额");
		try {
			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo("TK0" + orderId);
			changeRefundBillReq.setCatalogId(order.getOrderDetailPoList()
					.get(0).getCatalogId());
			changeRefundBillReq.setApplyRefundAmount(placeOrderResp
					.getPayableAmount().add(BigDecimal.TEN));

			changeRefundBillReq.setApplyRefundCount(1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口Code");

			Logger.verifyEquals(
					String.format("申请退款金额不能大于实际可退款金额",
							changeRefundBillReq.getRefundBillNo()),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证更新退货退款接口Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_005() {
		Logger.start(false, "退款单状态不正确,修改退款单失败");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			//申请改订单下第一个商品退款
			ApplyRefundReq applyRefundReq = RefundService
					.applyRefund(placeOrderResp.getOrderList().get(0));

			RefundService.approveRefundBillCall(applyRefundReq);

			String refundBillNo = applyRefundReq.getSalesRefundInfoList()
					.get(0).getRefundBillNo();
			changeRefundBillReq.setOrderId(placeOrderResp.getOrderList().get(0)
					.getOrderId());
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setCatalogId("ssss");
			changeRefundBillReq.setApplyRefundAmount(new BigDecimal(1));
			changeRefundBillReq.setApplyRefundCount(100);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口Code");

			Logger.verifyEquals(
					String.format("退款单%s已被审核通过,不能修改",
							changeRefundBillReq.getRefundBillNo()),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证更新退货退款接口Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_006() {
		Logger.start(true, "更新退款的金额大于商品价格+订单总运费");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			// 申请退款
			String refundBillNo = "TK0" + orderId;

			BigDecimal oriRefund = placeOrderResp.getPayableAmount();

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(new BigDecimal(100));
			changeRefundBillReq.setCatalogId(order.getOrderDetailPoList()
					.get(0).getCatalogId());
			changeRefundBillReq.setApplyRefundAmount(oriRefund);
			changeRefundBillReq.setApplyRefundCount(1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_007() {
		Logger.start(true, "更新商品退款金额加上部分商品运费");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			Order order = placeOrderResp.getOrderList().get(0);

			long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();

			// 申请退款
			String refundBillNo = "TK0" + orderId;

			BigDecimal oriRefund = placeOrderResp.getPayableAmount();

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(BigDecimal.ONE);

			changeRefundBillReq.setApplyRefundAmount(oriRefund
					.subtract(BigDecimal.ONE));

			changeRefundBillReq.setCatalogId(order.getOrderDetailPoList()
					.get(0).getCatalogId());

			changeRefundBillReq.setApplyRefundCount(order
					.getOrderDetailPoList().get(0).getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList().get(0).getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);

			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_008() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，部分退货退款，修改申请商品可退鉴别费金额小于商品可退鉴别费金额，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			RefundService.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(BigDecimal.ONE);
			changeRefundBillReq.setApplyRefundAuthenticateFee(BigDecimal.ONE);
			changeRefundBillReq.setApplyRefundAmount(oriRefund
					.subtract(BigDecimal.ONE));

			changeRefundBillReq.setCatalogId(order.getOrderDetailPoList()
					.get(0).getCatalogId());

			changeRefundBillReq.setApplyRefundCount(order
					.getOrderDetailPoList().get(0).getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_009() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，全部退货退款，修改退款金额>商品可退鉴别费金额+鉴别运费，修改退货退款成功");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService.buildStandApplyRefundReq(order);
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(BigDecimal.ONE);
			changeRefundBillReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()).add(BigDecimal.ONE));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(orderDetailPo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);
			expectedRefundBillPo.setUserAuthenticateFee(changeRefundBillReq.getApplyRefundAuthenticateFee());
			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_010() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，部分退货退款，修改全部退货退款，修改退货退款成功");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService.buildStandApplyRefundReq(order, 1);
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(oriRefund);
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(orderDetailPo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);
			expectedRefundBillPo.setUserAuthenticateFee(changeRefundBillReq.getApplyRefundAuthenticateFee());
			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_011() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，部分退货退款，修改申请金额小于商品可退鉴别费金额，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService.buildStandApplyRefundReq(order, 1);
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(1));
			changeRefundBillReq.setApplyRefundAmount(BigDecimal.ONE);
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能小于商品可退鉴别费金额", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_012() {
		Logger.start(true, "买手承担鉴定费和鉴定物流费, 接单后，部分退货退款，修改申请金额大于商品金额+运费，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.SELLER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.SELLER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService.buildStandApplyRefundReq(order, 1);
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq.setApplyRefundAuthenticateFee(BigDecimal.ONE);
			changeRefundBillReq.setApplyRefundAmount(BigDecimal.ONE);
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_013() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，先退一件商品，部分退货退款，修改申请金额大于剩余可退总金额，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			RefundService.applyRefundCall(RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1));
			
			// 修改退款
			String refundBillNo = "TK1" + orderId;
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1, refundBillNo);
			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq
					.setApplyRefundAuthenticateFee(order
							.getUserAuthenticateFee(
									orderDetailPo.getProductCount() - 1).add(
									order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(oriRefund);
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo.getProductCount() - 1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("申请退款金额不能大于实际可退款金额", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_014() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，先退一件商品，部分退货退款，修改申请数量大于剩余可退总数量，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			RefundService.applyRefundCall(RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1));
			
			// 修改退款
			String refundBillNo = "TK1" + orderId;
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1, refundBillNo);
			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq
					.setApplyRefundAuthenticateFee(order
							.getUserAuthenticateFee(
									orderDetailPo.getProductCount() - 1).add(
									order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(changeRefundBillReq.getApplyRefundAuthenticateFee().add(BigDecimal.ONE));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo.getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("申请退商品数量不能大于实际商品数量", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_015() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，先退一件商品，部分退货退款，修改剩余商品全退，修改退货退款成功");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			RefundService.applyRefundCall(RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1));
			
			// 修改退款
			String refundBillNo = "TK1" + orderId;
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1, refundBillNo);
			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq
					.setApplyRefundAuthenticateFee(order
							.getUserAuthenticateFee(
									orderDetailPo.getProductCount() - 1).add(
									order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(changeRefundBillReq
					.getApplyRefundAuthenticateFee().add(
							orderDetailPo.getProductPrice().multiply(
									new BigDecimal(orderDetailPo
											.getProductCount() - 1))));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount() - 1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(orderDetailPo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);
			expectedRefundBillPo.setUserAuthenticateFee(changeRefundBillReq.getApplyRefundAuthenticateFee());
			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_016() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，部分退货退款，修改申请金额等于商品可退鉴别费金额，修改退货退款失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService.buildStandApplyRefundReq(order, 1);
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(1));
			changeRefundBillReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(1));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能小于商品可退鉴别费金额", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_017() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，鉴定中心发货，先退一件商品，修改剩余商品全退，修改退款费用=剩余商品可退金额+剩余商品可退鉴定费+剩余运费+鉴定运费，修改失败");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);

			// 国际段
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
			Thread.sleep(3000);

			// 鉴定中心发货
			TradingCallService.authenticateDelivery(sellerId, orderId);
			Thread.sleep(3000);

			// 先申请一次退款
			RefundService.applyRefundCall(RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo,
							BigDecimal.ZERO, 1));
			
			// 修改退款
			String refundBillNo = "TK1" + orderId;
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1, refundBillNo);
			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq
					.setApplyRefundAuthenticateFee(order
							.getUserAuthenticateFee(
									orderDetailPo.getProductCount() - 1).add(
									order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(changeRefundBillReq
					.getApplyRefundAuthenticateFee().add(
							orderDetailPo.getProductPrice().multiply(
									new BigDecimal(orderDetailPo
											.getProductCount() - 1))));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount() - 1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("false",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					changeSalesRefundInfoCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_018() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 接单后，鉴定中心发货，先退一件商品，修改剩余商品全退，修改成功");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);

			// 国际段
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
			Thread.sleep(3000);

			// 鉴定中心发货
			TradingCallService.authenticateDelivery(sellerId, orderId);
			Thread.sleep(3000);

			// 先申请一次退款
			RefundService.applyRefundCall(RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo,
							BigDecimal.ZERO, 1));
			
			// 修改退款
			String refundBillNo = "TK1" + orderId;
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo, BigDecimal.ZERO,
							1, refundBillNo);
			RefundService.applyRefundCall(applyRefundReq);

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(order.getOrderFreight());
			changeRefundBillReq
					.setApplyRefundAuthenticateFee(order
							.getUserAuthenticateFee(
									orderDetailPo.getProductCount() - 1));
			changeRefundBillReq.setApplyRefundAmount(changeRefundBillReq
					.getApplyRefundAuthenticateFee().add(
							orderDetailPo.getProductPrice().multiply(
									new BigDecimal(orderDetailPo
											.getProductCount() - 1))));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount() - 1);

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(orderDetailPo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);
			expectedRefundBillPo.setUserAuthenticateFee(changeRefundBillReq.getApplyRefundAuthenticateFee());
			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeRefundBillV2_019() {
		Logger.start(true, "一个买家鉴定费商品，一个普通商品， 接单后，买家鉴定费商品全部退货退款，修改退款金额=商品可退金额+商品运费+商品可退鉴别费金额+鉴别运费，修改退货退款成功");
		try {

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticateWithTwoTypeProduct(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().stream()
					.filter(od -> od.getAuthenticateFlag() == true)
					.collect(Collectors.toList()).get(0);
			
			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			
			BigDecimal oriRefund = placeOrder.getPayableAmount();

			TradingCallService.payOrder(userId, oriRefund,
					placeOrder.getMainOrderId());

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			ApplyRefundReq applyRefundReq = RefundService
					.buildSingleApplyRefundReq(orderId, orderDetailPo,
							orderDetailPo.getFreight(),
							orderDetailPo.getProductCount());
			RefundService.applyRefundCall(applyRefundReq);

			// 修改退款
			String refundBillNo = "TK0" + orderId;

			changeRefundBillReq.setOrderId(orderId);
			changeRefundBillReq.setRefundBillNo(refundBillNo);
			changeRefundBillReq.setApplyRefundFreight(BigDecimal.ONE);
			changeRefundBillReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			changeRefundBillReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()).add(BigDecimal.ONE));
			changeRefundBillReq.setCatalogId(orderDetailPo.getCatalogId());
			changeRefundBillReq.setApplyRefundCount(orderDetailPo
					.getProductCount());

			changeSalesRefundInfoCall.setData(changeRefundBillReq);
			changeSalesRefundInfoCall.callService();

			Logger.verifyEquals("true",
					changeSalesRefundInfoCall.getString("success"),
					"验证更新退货退款接口返回正常");

			RefundBillPo expectedRefundBillPo = new RefundBillPo();

			expectedRefundBillPo.setRefundBillNo(refundBillNo);
			expectedRefundBillPo.setCatalogId(orderDetailPo.getCatalogId());

			expectedRefundBillPo.setTotalAmount(changeRefundBillReq
					.getApplyRefundAmount());

			expectedRefundBillPo.setProductCount(changeRefundBillReq
					.getApplyRefundCount());

			expectedRefundBillPo.setFreight(changeRefundBillReq
					.getApplyRefundFreight());

			expectedRefundBillPo.setOrderId(orderId);
			expectedRefundBillPo.setUserId(userId);
			expectedRefundBillPo.setSellerId(sellerId);
			expectedRefundBillPo.setTopspeedRefund(false);
			expectedRefundBillPo.setAfterReceiving(false);
			expectedRefundBillPo.setRefundStatus(0);
			expectedRefundBillPo.setUserAuthenticateFee(changeRefundBillReq.getApplyRefundAuthenticateFee());
			expectedRefundBillPo.setRefundBillStatus(1);

			RefundBillPo actualRefundBillPo = orderShardingWapper
					.selectRefundBillByBillNo(refundBillNo);

			RefundService.verifyRefundBillDb(expectedRefundBillPo,
					actualRefundBillPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
